import java.util.Arrays;

/*
剑指 Offer 40. 最小的k个数
解题思路：先按小到大排序，再返回第1个到第k个数字
 */
public class Offer40 {

  public static void main(String[] args) {
    int[] numbers = new Offer40().getLeastNumbers(new int[]{3, 2, 1}, 2);
    for (int number : numbers) {
      System.out.print(number + " ");
    }
  }

  public int[] getLeastNumbers(int[] arr, int k) {
    Arrays.sort(arr);
    int[]res = new int[k];
    for (int i = 0; i < k; i++) {
      res[i] = arr[i];
    }
    return res;
  }
}
